<?php
class Control_AnnounceData_edit {

	function edit() {
		$fileName = MooForm::request('fileName');
		$nameKey = MooObj::get('Control_AnnounceData')->getNameKey($fileName);
		$tagInfo = MooForm::request('tagInfo');
		
		$filePath = ROOT_PATH . "/notices/" . $fileName;
		
		MooView::set('fileName', $fileName);
		
		$data = array();
		while(false !== ($line = MooFile::readLine($filePath))) {
			 
			if (!$line) {
				continue;
			}
			$tmpArr = array();
			$lineArr = explode('	', $line);
			$data[$lineArr[1]] = $lineArr;
		}
		
		$dataValues = array();
		foreach ($data as $k => $v) {
			if($v[0] == "id") {
				$index = 0;
			} else {
				$index = $v[0];
			}
			$dataValues[$index] = $v;
		}
		 
		ksort($dataValues);
		
		unset($dataValues[0]);
		
		$minTitleNums = count($dataValues);
		MooView::set('minTitleNums', $minTitleNums);
		
		if($dataValues) {
			foreach($dataValues as $key => $val) {
				// 小标题
				MooView::set('minTitle'.$key, $val[1]);
				
				$minContent = str_replace("'", "|", $val[2]);	// ' 替换  | 
				$minContent = str_replace("\n", "", $minContent);	// 换行符号 去掉
				// 内容
				MooView::set('minContent'.$key, $minContent);
			}
		}
		
		$fileName = explode("_", $fileName);
		
		MooView::set('nameKey', $nameKey);
		
		$keyTitleFile = ROOT_PATH . "/notices/" . "keyTitle.txt";
		$keyTitle = MooFile::readAll($keyTitleFile);
		$keyTitleArr = MooJson::decode($keyTitle);
		
		if($keyTitleArr[$nameKey]) {
			$title = $keyTitleArr[$nameKey];
			MooView::set('title', $title);
		}
		
		// 设置tags 下拉
		MooObj::get('Control_Announce')->setTags();
		
		//echo $content;
		MooView::set('nowTagId', $tagInfo);
		
		MooView::set('type', 2);  // 编辑
		MooView::set('content', $content);
		
		MooView::render('editAnnounce');
	}
}